﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using QuaManSys.Common;
using QMSDAL;

namespace QuaManSys.InnerInfo
{
    public partial class InnerMainPage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["CurUser"] != null)
            {
                //根据当前用户的身份显示消息提醒栏
                ShowReminder((CurUser)Session["CurUser"]);
            }
            else
            {
                //跳转到登录页面
                Response.Redirect("~/Login.aspx");
            }
        }


        private void ShowReminder(CurUser user)
        {
            string emId = user.employeeId;
            //根据emID查询雇员角色
            string dept = user.department;  //雇员部门

            //查询当前用户对内部信息录入和内部收件箱具有的操作权限
            List<string> listOwnedReg = Permission.QueryOpers(emId, "1A");
            List<string> listOwnedRem = Permission.QueryOpers(emId, "1B");
            List<string> listOwnedQue = Permission.QueryOpers(emId, "1C");
            List<string> listDeptReg = Permission.QueryOpers(dept, "1A");
            List<string> listDeptRem = Permission.QueryOpers(dept, "1B");
            List<string> listDeptQue = Permission.QueryOpers(dept, "1C");

            if (listOwnedReg.Count + listOwnedRem.Count + listDeptReg.Count +
                listDeptRem.Count != 0)
            {
                bool completeOrNot = true;
                #region 重新登记

                //需要重新登记的信息
                if (listOwnedReg.Contains("A"))
                {
                    List<InnerQualityInfo> listInfoReg = Reminder.QueryInReminderList("登记", user);
                    if (listInfoReg.Count != 0)
                    {
                        completeOrNot = false;
                        int inPro = listInfoReg.Count;
                        HyperLink innerHref = new HyperLink();
                        pnlReminder.Controls.Add(innerHref);
                        innerHref.Text = "您共有" + inPro.ToString() +
                            "条内部质量信息需要登记。";
                        innerHref.NavigateUrl = "InnerInfoReminderBox.aspx";
                        pnlReminder.Controls.Add(new LiteralControl("<br />"));
                    }
                    else
                    {
                        //todo:如果没有需要重新登记的信息
                    }
                }
                #endregion

                #region 待分发

                //待分发的信息
                if (listOwnedRem.Contains("B0") || listDeptRem.Contains("B0"))
                {
                    List<InnerQualityInfo> listInfoDis = Reminder.QueryInReminderList("分发", user);
                    if (listInfoDis.Count != 0)
                    {
                        completeOrNot = false;

                        int inPro = listInfoDis.Count;
                        HyperLink innerHref = new HyperLink();
                        pnlReminder.Controls.Add(innerHref);
                        innerHref.Text = "您共有" + inPro.ToString() +
                            "条内部质量信息需要分发。";
                        innerHref.NavigateUrl = "InnerInfoReminderBox.aspx";
                        pnlReminder.Controls.Add(new LiteralControl("<br />"));

                    }
                }
                #endregion




                //待处理的消息

                #region 待处理

                if (listOwnedRem.Contains("B1") || listDeptRem.Contains("B1"))
                {
                    List<InnerQualityInfo> listInfoPro = Reminder.QueryInReminderList("处理", user);
                    if (listInfoPro.Count != 0)
                    {
                        int inPro = listInfoPro.Count;
                        completeOrNot = false;
                        //int inPro = processStatus.QueryInnerStatusPro(user).Count;
                        //int inRep = processStatus.QueryInnerResStatusPro(user).Count;
//                         if (inPro != 0)
//                         {
                            HyperLink innerHref = new HyperLink();
                            pnlReminder.Controls.Add(innerHref);
                            innerHref.Text = "您共有" + inPro.ToString() +
                                "条内部质量信息需要处理。";
                            //innerHref.Text += "其中您为责任部门的有" + inRep.ToString() + "条。";
                            innerHref.NavigateUrl = "InnerInfoReminderBox.aspx";
                            pnlReminder.Controls.Add(new LiteralControl("<br />"));
                        //}
                    }
                }
                #endregion

                #region 待归档的消息
                if (listOwnedRem.Contains("D1") || listDeptRem.Contains("D1"))
                {
                    List<InnerQualityInfo> list = Reminder.QueryInReminderList("归档", user);
                    if (list.Count != 0)
                    {
                        completeOrNot = false;
                        int inPro = list.Count;
                        HyperLink innerHref = new HyperLink();
                        pnlReminder.Controls.Add(innerHref);
                        innerHref.Text = "您共有" + inPro.ToString() +
                            "条内部质量信息需要归档。";
                        innerHref.NavigateUrl = "InnerInfoReminderBox.aspx";
                        pnlReminder.Controls.Add(new LiteralControl("<br />"));
                    }
                }
                #endregion


                if (completeOrNot)
                {
                    Label myLabelx = new Label();
                    myLabelx.Text = "当前您需要处理的内部信息已经处理完毕！";
                    pnlReminder.Controls.Add(myLabelx);
                    pnlReminder.Controls.Add(new LiteralControl("<br />"));
                }
            }
            else
            {
                if (listOwnedQue.Count + listDeptQue.Count != 0)
                {
                    Label myLabel = new Label();
                    myLabel.Text = "您是" + dept + "一般用户。可以查询本部门的质量信息。";
                    pnlReminder.Controls.Add(myLabel);
                    pnlReminder.Controls.Add(new LiteralControl("<br />"));
                    TurnToQueryList();
                }
                else
                {
                    Label myLabel = new Label();
                    myLabel.Text = "您当前权限不足，无法操作。请与管理员联系";
                    pnlReminder.Controls.Add(myLabel);
                    pnlReminder.Controls.Add(new LiteralControl("<br />"));
                }
            }
        }

        #region TurnToQueryList();
        private void TurnToQueryList()
        {
            HyperLink innerHref = new HyperLink();
            pnlReminder.Controls.Add(innerHref);
            innerHref.Text = "质量信息查询";
            innerHref.NavigateUrl = "~/InnerInfo/InnerInfoQueryList.aspx";
            pnlReminder.Controls.Add(new LiteralControl("<br />"));
        }
        #endregion
    }
}